﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace MaguenBrokersMVC.Models
{
    public class SeguroViajes : IValidatableObject
    {
        [ScaffoldColumn(false)]
        public virtual int Id { get; set; }

        [Required(ErrorMessage = "*")]
        public virtual string Nombre { get; set; }

        [Required(ErrorMessage = "*")]
        public virtual string Apellido { get; set; }

        [Required(ErrorMessage = "*")]
        [RegularExpression(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", ErrorMessage = "Ingrese un email válido por favor.")]
        [DataType(DataType.EmailAddress)]
        public virtual string Email { get; set; }

        [DisplayName("Tipo de Viaje")]
        [Required(ErrorMessage = "*")]
        public int TipoViajeId { get; set; }

        [Required(ErrorMessage = "*")]
        [DisplayName("Origen")]
        public int OrigenId { get; set; }

        [DisplayName("Destino")]
        [Required(ErrorMessage = "*")]
        public int DestinoId { get; set; }

        [DisplayName("Salida")]
        [DataType(DataType.Date)]
        [Required(ErrorMessage = "*")]
        public virtual DateTime FechaSalida { get; set; }

        [DisplayName("Regreso")]
        [DataType(DataType.Date)]
        [Required(ErrorMessage = "*")]
        public virtual DateTime FechaRegreso { get; set; }

        public virtual Edades Edades { get; set; }

        [DisplayName("Tipo de Viaje")]
        public virtual TipoViaje TipoViaje { get; set; }

        [DisplayName("Origen")]
        public virtual Origen Origen { get; set; }

        [DisplayName("Destino")]
        public virtual Destino Destino { get; set; }

        IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
        {
            var field = new[] { "FechaSalida", "FechaRegreso" };
            if (FechaSalida < DateTime.Now)
            {
                yield return new ValidationResult("Fecha inválida", field);
            }
            if (FechaRegreso <= FechaSalida)
            {
                yield return new ValidationResult("Fecha inválida", field);
            }
        }
    }
    public class TipoViaje
    {
        public int Id { get; set; }
        public string Nombre { get; set; }
    }
    public class Origen
    {
        public int Id { get; set; }
        public string Nombre { get; set; }
    }
    public class Destino
    {
        public int Id { get; set; }
        public string Nombre { get; set; }
    }
    public class Edades
    {
        [Range(1, 99, ErrorMessage = "*")]
        public int? Edad1 { get; set; }
        [Range(1, 99, ErrorMessage = "*")]
        public int? Edad2 { get; set; }
        [Range(1, 99, ErrorMessage = "*")]
        public int? Edad3 { get; set; }
        [Range(1, 99, ErrorMessage = "*")]
        public int? Edad4 { get; set; }
        [Range(1, 99, ErrorMessage = "*")]
        public int? Edad5 { get; set; }
    }
}